package com.example.server.web.controller;


import com.example.server.web.domain.Course;
import com.example.server.web.domain.RespBean;
import com.example.server.web.domain.dto.CourseParamDto;
import com.example.server.web.domain.page.PageQueryDto;
import com.example.server.web.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  课程 前端控制器
 * </p>
 *
 * @author 作者
 * @since 2023-04-04
 */
@RestController
@RequestMapping("/course")
@Api(tags = {"课程接口"})
public class CourseController {
    @Autowired
    private CourseService courseService;

    @ApiOperation("添加课程")
    @PostMapping("/add")
    public RespBean add(@RequestBody Course course){
        courseService.add(course);
        return RespBean.success("添加成功");
    }

    @ApiOperation("修改课程")
    @PostMapping("/modify")
    public RespBean modify(@RequestBody Course course){
        courseService.modify(course);
        return RespBean.success("修改成功");
    }

    @ApiOperation("删除课程")
    @GetMapping("/delete/{id}")
    public RespBean delete(@PathVariable("id") Long id){
        courseService.delete(id);
        return RespBean.success("删除成功");
    }

    @ApiOperation("分页查询课程")
    @GetMapping("/list")
    public RespBean list(CourseParamDto courseParamDto, PageQueryDto pageQueryDto){
        Map page = courseService.getPage(courseParamDto, pageQueryDto);
        return RespBean.success("查询成功",page);
    }
}
